package com.dqyt.lhq.service;

import com.dqyt.common.utils.UserInfoUtil;
import com.dqyt.khjc.bean.ResultMsg;
import com.dqyt.khjc.bean.User;
import com.dqyt.khjc.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Service
public class LhqUserService {


    @Autowired
    private UserMapper userMapper;

    /**
     * 查询某个角色的所有用户  lifubo(new)
     *
     * @param request
     * @return
     */
    public ResultMsg getUserByRole8(HttpServletRequest request) {
        ResultMsg ret = new ResultMsg(); // 声明一个返回值
        try {
            // 检查用户是否登录Token是否正确
            ret = UserInfoUtil.isAuthori_Web(request);
            // 如果有错误信息
            if (ret != null) {
                return ret;
            }
            ret = new ResultMsg(); // 声明一个返回值
            List<User> data = new ArrayList<>();
            List<User>  alldata = userMapper.getUserList2();
            for(User user:alldata){
                String jsStr = user.getRole();
                String [] jsArray =jsStr.split(",");
//                List<String> listB= Arrays.asList(jsArray);
//                if(listB.contains(role)){
//                    data.add(user);
//                }
                  if(user.getMtype()==1 || user.getMtype() ==8){
                      data.add(user);
                  }
            }
            ret.setCode(ResultMsg.SUCESS);
            ret.setMsg("查询成功");
            ret.setData(data);
        } catch (Exception e) {
            ret.setCode(ResultMsg.ERROR);
            ret.setMsg("未知的错误，请稍候再试！");
            e.printStackTrace();
        }
        return ret;
    }

}
